package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.publish.UnderPublishBo;
import com.zhuss.bean.vo.team.publish.DetailPublishVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.enums.PublishStatus;
import com.zhuss.exception.WpsException;
import com.zhuss.team.db.dao.ext.InvestPublishDao;
import com.zhuss.team.db.entity.InvestPublish;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/4/2 16:34
 */
@Component("publishUnder")
public class PublishUnder extends AbstractProcessor<Object, UnderPublishBo> implements Processor<Object, UnderPublishBo> {

    @Autowired
    private InvestPublishDao investPublishDao;

    @Autowired
    private PublishRead publishRead;

    @Override
    public Object process(UnderPublishBo bo) throws WpsException {
        InvestPublish ip = new InvestPublish();
        ip.setPublishId(bo.getPublishId());
        ip.setStatus(PublishStatus.撤回.key());

        ip.setModifier(bo.getConcurrentUserName());
        ip.setModifierId(bo.getConcurrentUserId());
        ip.setModifyTime(new Date());
        investPublishDao.updateByPrimaryKeySelective(ip);

        bo.setName(((DetailPublishVo)publishRead.detail(bo.getPublishId())).getInvestName());
        return null;
    }

    @Override
    public Object log(UnderPublishBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.协同发布.key());
        record.setAction(LogActionEnum.问卷发布下架.key());
        record.setTargetId(param.getPublishId());
        record.setTargetName(param.getName());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(UnderPublishBo underPublishBo) throws WpsException {

    }
}
